package pl.edu.mimuw.irs.rcp.controller.editor.workflow.handler;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.commands.CompoundCommand;

import pl.edu.mimuw.irs.core.model.design.net.Fragmentation;
import pl.edu.mimuw.irs.core.model.design.net.IRSNode;
import pl.edu.mimuw.irs.rcp.controller.editor.workflow.command.ExpandCommand;
import pl.edu.mimuw.irs.rcp.controller.editor.workflow.command.FragmentationCommand;

public abstract class AbstractFragmentationHandler extends AbstractNodeHandler {

	// *** Attributes
	
	protected abstract Fragmentation getFragmentation();
	
	// *** Methods

	@Override
	protected Object execute(ExecutionEvent event, CommandStack commandStack, IRSNode node) {
		Command command = new FragmentationCommand(node, getFragmentation());
		Command expand = new ExpandCommand(node, true);
		CompoundCommand compound = new CompoundCommand();
		compound.add(command);
		compound.add(expand);
		
		commandStack.execute(compound);
		return null;
	}
}
